<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="get">get</button>
    <button class="post">post</button>
</body>
<script>
    var getBtn = document.getElementsByClassName("get")[0];
    var postBtn = document.getElementsByClassName("post")[0];


    getBtn.onclick = function () {
        var id = 1;
        var ch = 55;
        var mh = 66;
        var en = 77;

        var xhr = new XMLHttpRequest();

        xhr.open("get", `../php/updateGradeByIdGET.php?id=${id}&ch=${ch}&mh=${mh}&en=${en}`, true);

        xhr.send();

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                var result = xhr.responseText;
                console.log(result);
                var data = JSON.parse(result);
                console.log(data);
                // var { status, msg } = data;
                // if (status) {

                //     loadGrade(); // 在不提交整个页面的情况下 实现页面的局部刷新
                // } else {
                //     alert(msg);
                // }
            }
        }
    }


    postBtn.onclick = function () {
        var id = 1;
        var ch = 55;
        var mh = 66;
        var en = 77;

        var xhr = new XMLHttpRequest();

        xhr.open("post", "../php/updateGradeByIdPost.php", true);

        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(`id=${id}&ch=${ch}&mh=${mh}&en=${en}`);

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                var result = xhr.responseText;
                console.log(result);
                var data = JSON.parse(result);
                console.log(data);
                // var { status, msg } = data;
                // if (status) {

                //     loadGrade(); // 在不提交整个页面的情况下 实现页面的局部刷新
                // } else {
                //     alert(msg);
                // }
            }
        }
    }


</script>

</html>